<%@ page contentType="text/html;charset=UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<c:set var="ctx" value="${pageContext.request.contextPath}"/>
<html>
<head>
	<title>消息管理</title>
</head>

<body>

	<div class="main-content-inner">
		<div class="breadcrumbs" id="breadcrumbs">
			<script type="text/javascript">
				try{ace.settings.check('breadcrumbs' , 'fixed')}catch(e){}
			</script>
			<ul class="breadcrumb">
				<li>
					<i class="ace-icon fa fa-home home-icon"></i>
					<a href="${ctx}/welcome">主页</a>
				</li>
				<li class="active">消息</li>
			</ul>
		</div>	
		
		<div class="page-content">
			
			<c:if test="${not empty message}">
				<div id="message" class="alert alert-success"><button data-dismiss="alert" class="close">×</button>${message}</div>
			</c:if>	
			
			<div class="page-header">
				<h1>
					消息
					<small>
						<i class="ace-icon fa fa-angle-double-right"></i>
						<c:if test="${action eq 'sendtagmsg'}">新增</c:if>
						<c:if test="${action eq 'update'}">修改</c:if>消息
					</small>
				</h1>
			</div>		
			
			<div class="row">
				<div class="col-xs-12">
					<!-- PAGE CONTENT BEGINS -->
					<div class="row">
						<div class="col-xs-12">

							<form id="inputForm" action="${ctx}/msg/${action}" method="post" class="form-horizontal">
								<input type="hidden" name="id" id="id" value="${msg.id}"/>
								<input type="hidden" name="op" id="op" value="${action}"/>
								<input type="hidden" name="tag" id="tag" value=""/>
								<input type="hidden" name="type" id="type" value="3"/>
								
								<%-- <div class="form-group">
									<label class="col-sm-3 control-label no-padding-right" for="form-field-1">类型: </label>
									<div class="col-sm-2">
										<select class="chosen-select form-control" id="type" name="type" data-placeholder="">
										   <c:if test="${action eq 'create'}">
										     <!--  <option value="" selected="selected">请选择</option> --> 
											  <option value="1" selected="selected">别名</option>
											 <!--   <option value="2">广播</option>
											  <option value="3">全部</option> --> 
										   </c:if>
										   <c:if test="${action eq 'update'}">
											  <option value="1" <c:if test="${msg.type eq '1' }">selected="selected"</c:if>>别名</option>
											   <!--  
											  <option value="2" <c:if test="${msg.type eq '2' }">selected="selected"</c:if>>广播</option>
											  <option value="3" <c:if test="${msg.type eq '3' }">selected="selected"</c:if>>全部</option>
											  --> 
										   </c:if>
										</select>
									</div>
								</div> --%>
								
								<div class="form-group">
									<label class="col-sm-3 control-label no-padding-right" for="form-field-1">创建时间: </label>
									<div class="col-sm-9">
										<input type="text" autocomplete="off" id="createdate" name="createdate"  value='<fmt:formatDate value="${msg.createdate}" pattern="yyyy-MM-dd HH:mm:ss" />' readonly="readonly" class="col-xs-10 col-sm-5"/>
									</div>
								</div>
									
								<div class="form-group">
									<label class="col-sm-3 control-label no-padding-right" for="form-field-1">推送用户: </label>
									<div class="col-sm-2">
										<select onchange="deviceChange()"  class="chosen-select form-control" id="device" name="device">
										   <c:if test="${action eq 'sendtagmsg'}">
											  <option value="1">Android</option>
											  <option value="2">IOS</option>
											 <!--  <option value="3">All</option> -->
											  <option value="4">全网用户</option>
											  <option value="5">离线用户</option>
										   </c:if>
										   <c:if test="${action eq 'update'}">
											  <option value="1" <c:if test="${msg.deltag eq '1' }">selected="selected"</c:if>>Android</option>
											  <option value="2" <c:if test="${msg.deltag eq '2' }">selected="selected"</c:if>>IOS</option>
											  <option value="4" <c:if test="${msg.deltag eq '4' }">selected="selected"</c:if>>全网用户</option>
											  <option value="5" <c:if test="${msg.deltag eq '5' }">selected="selected"</c:if>>离线用户</option>
										   </c:if>
										</select>
									</div>
								</div>
								
								
								
								<div class="form-group">
									<label class="col-sm-3 control-label no-padding-right" for="form-field-1">消息类型: </label>
									<div class="col-sm-2">
										<select class="chosen-select form-control" id="category" name="category" data-placeholder="" onchange="categorychange();">
										   <c:if test="${action eq 'sendtagmsg'}">
											  <option value="1" selected="selected">消息推送</option>
											  <option value="2">消息通知</option>
											  <!-- <option value="3">维护通知</option> -->
										   </c:if>
										   <c:if test="${action eq 'update'}">
											  <option value="1" <c:if test="${msg.category eq 1 }">selected="selected"</c:if>>消息推送</option>
										      <option value="2" <c:if test="${msg.category eq 2 }">selected="selected"</c:if>>消息通知</option>
										      <!-- <option value="3" <c:if test="${msg.category eq 3 }">selected="selected"</c:if>>维护通知</option> -->
										   </c:if>
										</select>
									</div>
								</div>
								
					   	        <div class="form-group">
									<label class="col-sm-3 control-label no-padding-right" for="form-field-1">通知标题: </label>
									<div class="col-sm-9">
										<input type="text" maxlength="8" autocomplete="off" id="title" name="title"  value="${msg.title}" placeholder="长度不超过8个字" readonly="readonly" class="col-xs-10 col-sm-5"/>
									</div>
								</div>
								<!--  -->
								<div class="form-group" style="display: none;">
									<label class="col-sm-3 control-label no-padding-right" for="form-field-1">跳转链接: </label>
									<div class="col-sm-9">
										<input type="text" autocomplete="off" id="link" name="link"  value="${msg.link}" class="col-xs-10 col-sm-5"/>
									</div>
								</div>
								
								<div class="form-group">
									<div>
									    <label class="col-sm-3 control-label no-padding-right" for="form-field-1">内容: </label>
									    <textarea maxlength="200" class="required" rows="10"  cols="10"  id="msg" name="msg" style="height:150px; width:500px;">${msg.msg}</textarea>
									</div>
								</div>
								
								
								<div class="clearfix form-actions">
									<div class="col-md-offset-3 col-md-9">
										<button onclick="formSubmit();" id="submit_btn" class="btn btn-info" type="button">
											<i class="ace-icon fa fa-check bigger-110"></i>
											发送
										</button>

										&nbsp; &nbsp; &nbsp;
										<button id="cancel_btn" class="btn" type="reset" onclick="history.back()">
											<i class="ace-icon fa fa-undo bigger-110"></i>
											返回
										</button>
									</div>
								</div>
								
							</form>
							
						</div>
					</div>			
				</div>
			</div>
		</div>
	</div>
	<script src="${ctx}/static/js/jquery.validate.min.js"></script>
	<script src="${ctx}/static/js/messages_bs_zh.js"></script>
    <script src="${ctx}/static/uploadify/jquery.uploadify.min.js" type="text/javascript"></script>
    <script>
		 function formSubmit(){
			var msg = $('#msg').val();
			var categoryValue = $('#category').val();
			if(categoryValue=='2' || categoryValue=='3'){
				var title = $('#title').val();
				if(title==null || title.length==0){
					alert("标题未填写");
					return false;
				}
			}
			<c:if test="${serverFixFlag eq true}">
			if(categoryValue=='3'){
				alert("当前已有维护通知了！请关闭后再添加！");
				return false;
			}
			</c:if>
			if(msg!=null && msg.length>0){
				$('#category').attr("disabled",false); 
				$('#inputForm').submit();
			}else{
				alert("消息内容没填写");
			}
		}
		
		function categorychange(){
			var categoryValue = $('#category').val();
			if(categoryValue=='2' || categoryValue=='3'){
				$('#title').attr("readonly",false); 
				$('#msg').attr("maxlength",200); 
			}else{
				$('#title').attr("readonly",true); 
				$('#msg').attr("maxlength",40); 
			}
		}
		
		function deviceChange(){
			var device = $('#device').val();
			if(device!=null && device.length>0){
				if(device=='5'){
					$('#category').val('1');
					$('#category').attr("disabled",true); 
					$('#title').attr("readonly",true); 
					$('#msg').attr("maxlength",40); 
				}else{
					$('#category').attr("disabled",false); 
					//$('#title').attr("readonly",false); 
					$('#msg').attr("maxlength",200); 
				}
			}
		}
		
		
	</script>
</body>
</html>